<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button v-if="$AUTH('hygl:hyUserAddress:add')" type="primary" icon="el-icon-plus" @click="add">
				</el-button>
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<!-- 日期时间范围 -->
					<el-date-picker v-model="search.createTime" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss"
						start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"></el-date-picker>
					<el-input v-model="search.hyUserAddressId" placeholder="收货地址" clearable></el-input>
					<el-input v-model="search.hyUserId" placeholder="会员id" clearable></el-input>
					<el-input v-model="search.copName" placeholder="公司名" clearable></el-input>
					<el-input v-model="search.linkUserName" placeholder="联系人" clearable></el-input>
					<el-input v-model="search.tel" placeholder="电话" clearable></el-input>
					<el-input v-model="search.wxCode" placeholder="微信" clearable></el-input>
					<el-input v-model="search.regionPath" placeholder="区域" clearable></el-input>
					<el-input v-model="search.district" placeholder="定位地址" clearable></el-input>
					<el-input v-model="search.address" placeholder="详细地址 门牌号" clearable></el-input>
					<el-input v-model="search.zipCode" placeholder="邮编" clearable></el-input>
					<el-input v-model="search.isDef" placeholder="是否默认" clearable></el-input>
					<el-input v-model="search.msg" placeholder="备注" clearable></el-input>
					<el-input v-model="search.state" placeholder="0 1" clearable></el-input>
					<el-input v-model="search.ghSysUserId" placeholder="跟踪人id" clearable></el-input>
					<el-input v-model="search.longitude" placeholder="经度" clearable></el-input>
					<el-input v-model="search.latitude" placeholder="纬度" clearable></el-input>
					<el-input v-model="search.deleted" placeholder="逻辑删除" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="hyUserAddressId" @selection-change="selectionChange" stripe>
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="收货地址" prop="district" width="150"></el-table-column>
				<el-table-column label="会员id" prop="hyUserId" width="150"></el-table-column>
				<el-table-column label="公司名" prop="copName" width="150"></el-table-column>
				<el-table-column label="联系人" prop="linkUserName" width="150"></el-table-column>
				<el-table-column label="电话" prop="tel" width="150"></el-table-column>
				<el-table-column label="微信" prop="wxCode" width="150"></el-table-column>
				<el-table-column label="区域" prop="regionPath" width="150"></el-table-column>
				<el-table-column label="定位地址" prop="district" width="150"></el-table-column>
				<el-table-column label="详细地址 门牌号" prop="address" width="150"></el-table-column>
				<el-table-column label="邮编" prop="zipCode" width="150"></el-table-column>
				<el-table-column label="是否默认" prop="isDef" width="150">

				</el-table-column>
				<el-table-column label="备注" prop="msg" width="150"></el-table-column>
				<el-table-column label="0 1" prop="state" width="150"></el-table-column>
				<el-table-column label="跟踪人id" prop="ghSysUserId" width="150"></el-table-column>
				<el-table-column label="经度" prop="longitude" width="150"></el-table-column>
				<el-table-column label="纬度" prop="latitude" width="150"></el-table-column>
				<el-table-column label="逻辑删除" prop="deleted" width="150"></el-table-column>
				<!--    <el-table-column label="创建时间" prop="createTime" width="150" :formatter="formatDate"></el-table-column>-->
				<el-table-column label="操作" fixed="right" align="right">
					<template #default="scope">
						<el-button v-if="$AUTH('hygl:hyUserAddress:edit')" type="text" size="small"
							@click="table_edit(scope.row, scope.$index)">编辑</el-button>
						<el-divider direction="vertical"></el-divider>
						<el-button v-if="$AUTH('hygl:hyUserAddress:del')" type="text" size="small"
							@click="table_del(scope.row, scope.$index)">删除</el-button>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>

	<hyUserAddressEdit-dialog v-if="dialog.hyUserAddressEdit" ref="hyUserAddressEditDialog" @success="handleSaveSuccess"
		@closed="dialog.hyUserAddressEdit=false"></hyUserAddressEdit-dialog>
</template>

<script>
	import hyUserAddressEditDialog from './hyUserAddressEdit'; //1--导入
	export default {
		name: 'hyUserAddress',
		components: {
			hyUserAddressEditDialog //2发布
		},
		data() {
			return {
				dialog: {
					hyUserAddressEdit: false
				},
				apiObj: this.$API.hygl.hyUserAddress.list,
				selection: [],
				search: {
					keyword: null,
					createTime: null
				}
			}
		},
		methods: {
			//添加
			add() {
				this.dialog.hyUserAddressEdit = true
				this.$nextTick(() => {
					this.$refs.hyUserAddressEditDialog.open()
				})
			},
			//编辑
			table_edit(row) {
				this.dialog.hyUserAddressEdit = true
				this.$nextTick(() => {
					this.$refs.hyUserAddressEditDialog.open('edit').setData(row)
				})
			},
			//删除
			async table_del(row) {
				var confirm = await this.$confirm('确定删除选中的项吗？', '提示', {
					confirmButtonText: 'ok',
					type: 'warning'
				}).catch(() => {})
				if (confirm !== 'confirm') {
					return false;
				}
				var res = await this.$API.test.hyUserAddress.delete.delete(row.hyUserAddressId);
				if (res.code === 2000) {
					this.$refs.table.refresh();
					this.$message.success("删除成功");
				} else {
					this.$alert(res.message, "提示", {
						type: 'error'
					});
				}
			},
			//表格选择后回调事件
			selectionChange(selection) {
				this.selection = selection;
			},
			//搜索
			upsearch() {
				this.$refs.table.upData(this.search);
			},
			//本地更新数据
			handleSaveSuccess() {
				this.$refs.table.refresh();
			},
			handlePermissionSuccess() {
				this.$refs.table.refresh();
			},
			handleDataSuccess() {
				this.$refs.table.refresh();
			},
			formatDate(row, column) { // 获取单元格数据
				let data = row[column.property];
				if (data == null) {
					return null;
				}
				let dt = new Date(data);
				return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt
					.getMinutes() + ':' + dt.getSeconds();
			},
		}
	}
</script>
<style>
</style>
